package com.zhuanyongjin.server;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.zhuanyongjin.dao.member_yongjinDao;
import com.zhuanyongjin.dao.new_informationDao;
import com.zhuanyongjin.dao.yongjinDao;
import com.zhuanyongjin.dao.impl.member_yongjinDaoImpl;
import com.zhuanyongjin.dao.impl.new_informationDaoImpl;
import com.zhuanyongjin.dao.impl.yongjinDaoImpl;
import com.zhuanyongjin.util.Calenda;

public class completeyongjinServlet extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		int yongjin_id=Integer.parseInt(request.getParameter("yongjin_id"));
		int member_id=Integer.parseInt(request.getParameter("member_id"));
		int yongjin=Integer.parseInt(request.getParameter("yongjin"));
		Calenda C=new Calenda();
		String now=C.getNowTime().toString();
		//完成时更新member_yongjin和yongjin表中的数据，同时将new_information中插入个人信息
        member_yongjinDao m=new member_yongjinDaoImpl();
        yongjinDao y=new yongjinDaoImpl();
        new_informationDao n=new new_informationDaoImpl();
        //完成第一步
        boolean b1=m.updatemember_yongjin(member_id,yongjin_id);
        boolean b2=y.updateyongjin(yongjin_id);
        System.out.println(b1);
        System.out.println(b2);
        if(b1==true&&b2==true){
        	//完成第二步
            boolean b=n.insertnew_information(member_id,yongjin);
            if(b==true)
            {
                out.print("success");
            }
            else 
            	out.println("error");
        }
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
